package dao;

import java.util.List;

import hbt.HibernateUtil;

import org.hibernate.Session;
import org.hibernate.SessionFactory;

import entities.Alumno;

public class AlumnoDAO {
	
	private static AlumnoDAO instancia;
	
	private AlumnoDAO(){}
	
	public static AlumnoDAO getInstancia()
	{
		if(instancia == null)
			instancia = new AlumnoDAO();
		return instancia;
	}
	
	public List<Alumno> obtenerAlumnos() {
		SessionFactory sf =  HibernateUtil.getSessionFactory();
		Session session = sf.openSession();
//		List<Alumno>alumnos=(List<Alumno>)session.createQuery("select * from Alumno where a.id=?").setInteger(0, alumno.getId()).list();
		@SuppressWarnings("unchecked")
		List<Alumno>alumnos=(List<Alumno>)session.createQuery("select * from Alumno").list();
		return alumnos;
	}
	
	@SuppressWarnings("null")
	public List<String> getListaAlumnos(){
		List<String> miLista = null;
		List<Alumno> listaObj = this.obtenerAlumnos();
		for (int i=0; i<listaObj.size(); i++){
			miLista.add(listaObj.get(i).getNombre());
		}
		return miLista;
	}
}